//
//  QueryCompanyTableView.m
//  YaoHeAPP
//
//  Created by xyh on 16/7/5.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "QueryCompanyTableView.h"
#import "QueryCompanyResultModel.h"
#import "CompanyItemModel.h"

@interface QueryCompanyTableView ()<UITableViewDelegate,UITableViewDataSource>
{
    CompanyItemModel *_companyItemModel;

}
@end

@implementation QueryCompanyTableView

- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
    self = [super initWithFrame:frame style:style];
    if (self) {
    
        self.dataSource=self;
        self.delegate=self;
        self.backgroundColor=[UIColor colorWithRed:230/255.0 green:232/255.0 blue:241/255.0  alpha:1];
        self.scrollEnabled = NO;
        self.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        
    }
    return self;
}

#pragma  mark--------------表格代理方法-----------------
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    return _QueryCompanyList.count+1;
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //创建cell
    
    NSString *identifier = [NSString stringWithFormat:@"companyTableViewCell%ld%ld",(long)indexPath.section,(long)indexPath.row];
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    if (cell == nil) {
        
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.selectionStyle=UITableViewCellSeparatorStyleSingleLine;
        cell.accessoryType=UITableViewCellAccessoryNone;
        
    }
    
    if (indexPath.row==_QueryCompanyList.count) {
        
        cell.textLabel.text=@"关闭";
        cell.textLabel.textAlignment=NSTextAlignmentRight;
    }else{
    
         _companyItemModel=_QueryCompanyList[indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentLeft;
        cell.textLabel.text=_companyItemModel.COMPANY_NAME;
        cell.textLabel.font=Font(12);
    }
    
    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.row==_QueryCompanyList.count) {
        
        if (self.cancelActionBlock) {
            self.cancelActionBlock();
        }
    }else{
    
        if (self.didSelectRowBlock) {
            self.didSelectRowBlock(indexPath.row);
        }

    }
    
    
}




@end
